package com.centronix.web;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import com.centronix.bean.ComboBean;
import com.centronix.domain.ProductCatagory;
import com.centronix.domain.ProductType;
import com.centronix.manager.ProductCatManager;
import com.centronix.manager.ProductTypeManager;
import com.centronix.util.WebUtil;

@ManagedBean(name = "productTypeBean")
@SessionScoped
public class ProductTypeBean implements Serializable{

	private static final long serialVersionUID = 1L;

	@ManagedProperty("#{productTypeManager}")
    private ProductTypeManager productTypeManager;
	
	@ManagedProperty("#{productCatManager}")
    private ProductCatManager productCatManager;
	
	
	private List<ComboBean> productCatComboList =  new ArrayList<ComboBean>(0);
	private Date selectedDate = new Date();
	
	private String ProductTypeTypeCode = "";
	private ProductType newProductType = new ProductType();
	private ProductType selectedProductType = new ProductType();
	
	private List<ProductType> allProductType = new ArrayList<ProductType>(0);
	
	private boolean dataVisible = false;
	private String selectedProductCat = "";

	public String findAllProductTypes(){
		allProductType = productTypeManager.findAllProductType();
		productCatComboList = productCatManager.getProductCatCombo();
		dataVisible = true;
		return "producttype";
	}
	
	public String saveNewProductType(){
		int proCat = Integer.valueOf(selectedProductCat);
		ProductCatagory productCatagory = new ProductCatagory();
		productCatagory.setCatagoryId(proCat);
		newProductType.setProductCatagory(productCatagory);
		productTypeManager.saveProductType(newProductType);
		allProductType = productTypeManager.findAllProductType();
		newProductType = new ProductType();
		selectedProductCat = "";
		WebUtil.showSuccessfulMessage("Record Saved!");
		return "";
	}
	
	public String updateProductType(){
		productTypeManager.saveProductType(selectedProductType);
		allProductType = productTypeManager.findAllProductType();
		selectedProductType = new ProductType();
		selectedProductCat = "";
		WebUtil.showSuccessfulMessage("Record Updated!");
		return "";
	}
	
	public String deleteProductType(){
		productTypeManager.deleteProductType(selectedProductType.getTypeId());
		allProductType = productTypeManager.findAllProductType();
		selectedProductType = new ProductType();
		selectedProductCat = "";
		WebUtil.showSuccessfulMessage("Record Deleted!");
		return "";
	}

	public ProductTypeManager getProductTypeManager() {
		return productTypeManager;
	}

	public void setProductTypeManager(ProductTypeManager productTypeManager) {
		this.productTypeManager = productTypeManager;
	}

	public ProductCatManager getProductCatManager() {
		return productCatManager;
	}

	public void setProductCatManager(ProductCatManager productCatManager) {
		this.productCatManager = productCatManager;
	}

	public List<ComboBean> getProductCatComboList() {
		return productCatComboList;
	}

	public void setProductCatComboList(List<ComboBean> productCatComboList) {
		this.productCatComboList = productCatComboList;
	}

	public Date getSelectedDate() {
		return selectedDate;
	}

	public void setSelectedDate(Date selectedDate) {
		this.selectedDate = selectedDate;
	}

	public String getProductTypeTypeCode() {
		return ProductTypeTypeCode;
	}

	public void setProductTypeTypeCode(String productTypeTypeCode) {
		ProductTypeTypeCode = productTypeTypeCode;
	}

	public ProductType getNewProductType() {
		return newProductType;
	}

	public void setNewProductType(ProductType newProductType) {
		this.newProductType = newProductType;
	}

	public ProductType getSelectedProductType() {
		return selectedProductType;
	}

	public void setSelectedProductType(ProductType selectedProductType) {
		this.selectedProductType = selectedProductType;
	}

	public List<ProductType> getAllProductType() {
		return allProductType;
	}

	public void setAllProductType(List<ProductType> allProductType) {
		this.allProductType = allProductType;
	}

	public boolean isDataVisible() {
		return dataVisible;
	}

	public void setDataVisible(boolean dataVisible) {
		this.dataVisible = dataVisible;
	}

	public String getSelectedProductCat() {
		return selectedProductCat;
	}

	public void setSelectedProductCat(String selectedProductCat) {
		this.selectedProductCat = selectedProductCat;
	}
	


	

}
